<script lang="ts" setup>
  import { createVNode } from 'vue';
  import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
  import Button from '@sscd/button';
  import Modal from '@sscd/modal';
  const showConfirm = () => {
    Modal.confirm({
      title: 'Do you want to delete these items?',
      icon: createVNode(ExclamationCircleOutlined),
      content: 'When clicked the OK button, this dialog will be closed after 1 second',
      onOk() {
        // vue3.4+版本可能会出现Modal无法正常关闭，需调用Modal.remove()
        return new Promise((resolve, reject) => {
          setTimeout(Math.random() > 0.5 ? resolve : reject, 1000);
          Modal.remove();
        }).catch(() => console.log('Oops errors!'));
      },
      onCancel() {
        // vue3.4+版本可能会出现Modal无法正常关闭，需调用Modal.remove()
        console.log('cancel');
        Modal.remove();
      },
    });
  };
</script>

<template>
  <div class="demo">
    <div class="demo-title">确认对话框(promise)</div>
    <div class="demo-content">
      <Button @click="showConfirm">Confirm</Button>
    </div>
  </div>
</template>
